<?php

//如果有post表单就走进去条件判断
if($_POST)
{
    //cookie中存放的
    $cookie = isset($_COOKIE['imgcode']) ? trim($_COOKIE['imgcode']) : '';

    //表单提交的
    $imgcode = isset($_POST['imgcode']) ? trim($_POST['imgcode']) : '';

    //大小写转换 统一
    var_dump($imgcode, $cookie);

    if(strtolower($imgcode) != strtolower($cookie))
    {
        echo "验证码输入错误";
    }else
    {
        echo "验证码输入正确";
    }
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form method="post">
        <img src="imgcode.php" onclick="this.src = `imgcode.php?${Math.random()}`" /><br />
        验证码：<input type="text" name="imgcode" required placeholder="请输入验证码" /><br />
        <button type="submit">提交</button>
    </form>
</body>
</html>